package com.lagou.homework.clientserverchat;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.*;

/**
 * @author Rentaian
 */
public class Servers extends Thread {
    private ServerSocket ss = null;
    static List<Socket> ls = new LinkedList<>();
    @Override
    public void run() {
        try {
            ss = new ServerSocket(8888);
            while(true) {
                System.out.println("等待客户端的连接请求!");
                Socket s = ss.accept();
                System.out.println("------------------------已连接上");
                ls.add(s);
                System.out.println("-----------------------已添加上" + ls.size());
                new ServerThread(s).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(null != ss) {
                try {
                    ss.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
